﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// 学生类
class Student
{
    public int StudentId { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }

    public Student(int studentId, string name, int age)
    {
        StudentId = studentId;
        Name = name;
        Age = age;
    }
}

// 测试类
class Program
{
    static void Main(string[] args)
    {
        List<Student> studentList = new List<Student>();

        // 增加一个学生
        studentList.Add(new Student(1, "张三", 18));
        studentList.Add(new Student(2, "李四", 19));
        studentList.Add(new Student(3, "王五", 20));

        // 修改一个指定学号的学生
        ModifyStudent(studentList, 2, "赵六", 21);

        // 删除一个学生
        DeleteStudent(studentList, 1);

        // 查询一个指定学号的学生
        Student student = FindStudent(studentList, 3);
        if (student != null)
        {
            Console.WriteLine("学号：{0}，姓名：{1}，年龄：{2}", student.StudentId, student.Name, student.Age);
        }
        else
        {
            Console.WriteLine("未找到指定学号的学生");
        }

        // 遍历所有学生
        TraverseStudents(studentList);
    }

    // 修改一个指定学号的学生
    static void ModifyStudent(List<Student> studentList, int studentId, string newName, int newAge)
    {
        Student student = studentList.Find(s => s.StudentId == studentId);
        if (student != null)
        {
            student.Name = newName;
            student.Age = newAge;
            Console.WriteLine("已修改学号为 {0} 的学生信息", studentId);
        }
        else
        {
            Console.WriteLine("未找到指定学号的学生");
        }
    }

    // 删除一个学生
    static void DeleteStudent(List<Student> studentList, int studentId)
    {
        Student student = studentList.Find(s => s.StudentId == studentId);
        if (student != null)
        {
            studentList.Remove(student);
            Console.WriteLine("已删除学号为 {0} 的学生信息", studentId);
        }
        else
        {
            Console.WriteLine("未找到指定学号的学生");
        }
    }

    // 查询一个指定学号的学生
    static Student FindStudent(List<Student> studentList, int studentId)
    {
        Student student = studentList.Find(s => s.StudentId == studentId);
        return student;
    }

    // 遍历所有学生
    static void TraverseStudents(List<Student> studentList)
    {
        Console.WriteLine("所有学生信息：");
        foreach (Student student in studentList)
        {
            Console.WriteLine("学号：{0}，姓名：{1}，年龄：{2}", student.StudentId, student.Name, student.Age);
        }
    }
}
